<?php
defined('BASEPATH') OR exit('No direct script access allowed');
?>
<?php $this->load->view('admin/header.html')?>
<script type="text/javascript" src="<?php echo base_url()?>common/js/validateForm.js"></script>
<script type="text/javascript" src="<?php echo base_url()?>common/js/ck.js"></script>
<script type="text/javascript">
    function Success(data) {
        $.Success(data);
    }
    $(function () {
        $(".tableBasic form").each(function () {
            var itemsId = $(this).attr('id');
            $.validate_cooperationWeight(itemsId);
        });
    });

    function Del(cooperation_id)
    {
        var url = "/admin/cooperation/del_cooperation/" + cooperation_id + "?returnurl=<?php echo 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']?>";
        layer.confirm("确定删除", function () {
            $.post(url, null, function (data) {
                var jsonData = $.parseJSON(data);
                if (jsonData.Statu == 'ok') {
                    Success(jsonData)
                }
                else {
                    Success(jsonData)
                }
            })
        }, function () {
            layer.msg('取消删除', { icon: 0 });
        })
    }
    function BatchDel() {
        layer.confirm("确定要删除？", function (index) {
            if ($("#checkboxVal").val().length <= 0) {
                layer.msg('未选择删除项，删除取消', { icon: 0 });
                return false;
            }
            var url = "/admin/cooperation/batch_del_cooperation?returnurl=<?php echo 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']?>";
            $.post(url, { "items": $("#checkboxVal").val() }, function (data) {
                if (data.Statu == "ok") {
                    Success(data)
                    $("#allcheck").attr("checked", false)
                } else {
                    Success(data)
                }
            }, "json")
        }, function () {
            layer.msg('取消删除', { icon: 0 });
        })
    }


</script>
<div id="dcMain">
    <!-- 当前位置 -->
    <div id="urHere">
        DouPHP 管理中心
        <?php foreach($crumbs_items as $crumbs_item):?>
        <b>></b><a href="<?php echo $crumbs_item[0]?>"><?php echo $crumbs_item[1]?></a>
        <?php endforeach;?>
    </div>
    <div id="manager" class="mainBox" style="height:auto!important;height:550px;min-height:550px;">
        <h3>
            <a href="<?php echo site_url('admin/cooperation/addcooperation/'.$menuid);?>" class="actionBtn">添加合作伙伴</a><?php echo end($crumbs_items)[1]?>
        </h3>
        <table width="100%" border="0" cellpadding="8" cellspacing="0" class="tableBasic">
            <tr>
                <th width="50" align="center"><label for="allcheck">选择</label> <input type="checkbox" id="allcheck" name="allcheck" class="allcheck" /></th>
                <th width="30" align="center">编号</th>
                <th width="150" align="center">标题</th>
                <th align="left">图片</th>
                <th align="left">权重</th>
                <th align="center">操作</th>
            </tr>
            <?php foreach($cooperationlist as $cooperation_item):?>
            <tr>
                <td align="center"><input type="checkbox" name="cklist" value="<?php echo $cooperation_item->cooperation_id;?>" /></td>
                <td align="center"><?php echo $cooperation_item->cooperation_id;?></td>
                <td align="center"><?php echo $cooperation_item->title;?></td>
                <td><img src="<?php echo $cooperation_item->imgurl;?>" style="height:40px;width:35px;" /></td>
                <td align="center">
                    <form id="ajax_form_<?php echo $cooperation_item->cooperation_id?>" method="post" action="<?php echo site_url('admin/cooperation/set_cooperation_weight/'.$cooperation_item->cooperation_id)?>?returnurl=<?php echo 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']?>">
                        <input style="border:1px solid #949191;" type="text" name="weight" id="weight_<?php echo $cooperation_item->cooperation_id?>" value="<?php echo $cooperation_item->weight;?>" />&nbsp;<input type="submit" class="btn-mini" value="更新" />
                    </form>
                </td>
                <td align="center">
                    <a href="<?php echo site_url('admin/cooperation/editcooperation/'.$cooperation_item->cooperation_id)?>">编辑</a>|
                    <a href="javascript:Del(<?php echo $cooperation_item->cooperation_id?>)">删除</a>
                </td>
            </tr>
            <?php endforeach; ?>
            <tr>
                <td colspan="10"><a href="javascript:BatchDel()">全部删除</a></td>
            </tr>
        </table>
        <input type="hidden" value="" id="checkboxVal" />
        <div class='page'>
            <?php echo $links?>
        </div>
    </div>
</div>